<template>
  <el-input
    v-model="val"
    placeholder="请输入内容"
    :type="typeObj[$attrs.attributeType]"
    :disabled="$attrs.disabled"
  ></el-input>
</template>
<script>
// 单行文本组件
export default {
  props: {
    value: {
      type: [ String, Number ],
      default: ''
    },
    type: {
      type: [ String ],
      default: 'text'
    }
  },
  data () {
    return {
      typeObj: {
        inputNum: 'number',
        text: 'text',
        textarea: 'textarea'
      },
      val: ''
    }
  },
  watch: {
    val: {
      handler: 'handler',
      deep: true
    },
    value (val) {
      this.val = val;
    }
  },
  mounted () {
    this.val = this.value;
  },
  methods: {
    /**
     * @name handler
     * @description watch函数
     * @author cjs1992
     * @date 2019-11-06 13:21:14
     */
    handler (val) {
      // 防止val不支持trim方法
      try {
        val = val.trim();
      } catch (error) {
        console.log(error);
      }
      this.$emit('input', val);
    }
  }
}
</script>
